#include "ShipLoader.h"
#include "..\Util\FileUtil.h"
#include "..\Util\Utils.h"
#include <iostream>

using namespace std;
using namespace util;

#define SEPARATOR '|'

ShipLoader::ShipLoader(const string &shipConfigFile)
{
	if (FileUtil::fileExists(shipConfigFile))
	{
		ifstream shipFile(shipConfigFile);

		string line;
		while (getline(shipFile, line))
		{
			size_t delimiter = line.find_first_of(SEPARATOR);
			string key = line.substr(0, delimiter);

			delimiter = delimiter+1;
			string tag = line.substr(delimiter);
			
			shipTags.insert(pair<string, string>(Utils::trim(key), Utils::trim(tag)));
		}
	}
}

ShipLoader::~ShipLoader()
{
}

string ShipLoader::getShipTag(const string &type)
{
	if (shipTags.find(type) != shipTags.end())
	{
		return shipTags[type];
	}
	else return "";
}
